<template>
	<view class="count">
		<u-button @click="throttleShovel" type="primary" class="button">斗 +1</u-button>
		<u-button @click="throttleCar" type="success" class="button">车 +1</u-button>
	</view>
</template>

<script setup>
	import {
		throttle
	} from "lodash"
	import {
		countAdd
	} from '@/api/index.js';
	import {
		onMounted
	} from "vue";
	//斗增加
	const shovelClick = async () => {
		const userID = uni.getStorageSync('userID') || '';
		let res = await countAdd(userID, 0);
		uni.showToast({
			icon: "none",
			title: res.msg,
		})
	}
	const throttleShovel = throttle(shovelClick, 1000)
	//车增加
	const carClick = async () => {
		const userID = uni.getStorageSync('userID') || '';
		let res = await countAdd(userID, 1);
		uni.showToast({
			icon: "none",
			title: res.msg,
		})
	}
	const throttleCar = throttle(carClick, 1000)

	onMounted(() => {
		throttleShovel = null;
		throttleCar = null
	})
</script>

<style lang="scss">
	.count {
		padding: 20rpx;
		display: flex;
		flex-direction: column;

		.button {
			margin-top: 40rpx;
			width: 100%;
		}
	}
</style>